package org.jeecg.modules.qyxx.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.aspect.annotation.AutoLog;
import org.jeecg.modules.fk.entity.DjUserInfo;
import org.jeecg.modules.fk.service.IDjUserInfoService;
import org.jeecg.modules.qyxx.entity.BgSwzbjcOrder;
import org.jeecg.modules.qyxx.entity.TycQsgg;
import org.jeecg.modules.qyxx.entity.TycSswf;
import org.jeecg.modules.qyxx.entity.TycXzcf;
import org.jeecg.modules.qyxx.entity.req.BgNsrjbxxReq;
import org.jeecg.modules.qyxx.entity.req.SsjcSssjDTO;
import org.jeecg.modules.qyxx.entity.resp.BgQyjbxxBgVo;
import org.jeecg.modules.qyxx.service.*;
import org.jeecg.modules.qyxx.util.ListUtil;
import org.jeecg.modules.qyxxora.entity.ZbjkSwzbjkjg;
import org.jeecg.modules.qyxx.entity.qo.ZbjkSwzbjkjgQo;
import org.jeecg.modules.qyxx.entity.req.ZbjkSwzbjkjgReq;
import org.jeecg.modules.qyxxora.service.IZbjkSwzbjkjgService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * @Description: 税务指标监控结果
 * @Author: ZJJ
 * @Date: 2021-06-01
 * @Version: V1.0
 */
@Slf4j
@Api(tags = "涉诉数据")
@RestController
@RequestMapping("/taxIndicators")
public class TaxIndicatorsController {
    @Autowired
    private IZbjkSwzbjkjgService zbjkSwzbjkjgService;
    @Autowired
    private ICjQyxxStatusService cjQyxxStatusService;
    @Autowired
    private IDjUserInfoService djUserInfoService;
    @Autowired
    private ITycLsgsxxLsmcService tycLsgsxx;
    @Autowired
    private ITycQsggService tycQsggService;
    @Autowired
    private ITycXzcfService tycXzcfService;
    @Autowired
    private ITycSswfService tycSswfService;
    @Autowired
    private ListUtil<BgQyjbxxBgVo> listUtil;


    @AutoLog(value = "获取税务指标监控结果")
    @PostMapping(value = "/zbjkSwzbjkjg")
    public Result<?> zbjkSwzbjkjg(@RequestBody ZbjkSwzbjkjgReq req) {
        ZbjkSwzbjkjg swzbjkjg = zbjkSwzbjkjgService.zbjkSwzbjkjg(req.getDjxh(), req.getSsny());
        if (swzbjkjg == null) {
            // 判断当前企业所属年月是否已经采集数据
            if (cjQyxxStatusService.getCjInfo(req.getDjxh(), req.getSsny()) > 0) {
                // 有采集数据还没加工.
                return Result.error("报告正在生成中");
            }
            return Result.error("暂时没有该数据报告");
        }
        cjQyxxStatusService.getCjInfo(req.getDjxh(), req.getSsny());
        return Result.OK(swzbjkjg);
    }

    @AutoLog(value = "工商信息变更")
    @PostMapping(value = "/gsxxbg")
    @ApiOperation("工商信息变更")
    public Result<List<BgQyjbxxBgVo>> gsxxbg(@RequestBody SsjcSssjDTO req) {
        List<BgQyjbxxBgVo> list = tycLsgsxx.gsxxbg(req);
        int total = list.size();
//        if (total == 0) {
//            Result<List<BgQyjbxxBgVo>> result = new Result<>();
//            return result.error500("查询不到企业的工商信息变更数据");
//        }
        /*if (total == 0) {
            return Result.error("查询不到企业的工商信息变更数据");
        }*/
        /*list = list.stream().sorted(Comparator.comparing(BgQyjbxxBgVo::getBgsj).reversed())
                .collect(Collectors.toList());
        list = listUtil.page(list, req.getPageSize(), req.getPageNo());
        Page<BgQyjbxxBgVo> page = new Page<>();
        page.setCurrent(req.getPageNo());
        page.setSize(req.getPageSize());
        page.setTotal(total);
        page.setRecords(list);*/
        /*HashMap<String, Object> map = new HashMap<>();
        map.put("datalist", list);
        map.put("total", total);
        map.put("size", req.getPageSize());
        map.put("page", req.getPageNo());*/
        return Result.OK(list);
    }

    @AutoLog(value = "欠税公告")
    @PostMapping(value = "/qsgg")
    @ApiOperation("欠税公告")
    //public Result<Page<TycQsgg>> qsgg(@RequestBody SsjcSssjDTO req) {
    public Result<List<TycQsgg>> qsgg(@RequestBody SsjcSssjDTO req) {
        // Page<TycQsgg> qsgg = tycQsggService.qsgg(req);
        List<TycQsgg> qsgg = tycQsggService.qsgg(req);
/*        long total = qsgg.size();
        if (total == 0) {
            Result<List<TycQsgg>> result = new Result<>();
            return result.error500("查询不到企业的欠税数据");
        }*/
        return Result.OK(qsgg);
    }

    @AutoLog(value = "行政处罚")
    @PostMapping(value = "/xzcf")
    @ApiOperation("行政处罚")
    // public Result<Page<TycXzcf>> xzcf(@RequestBody SsjcSssjDTO req) {
    public Result<List<TycXzcf>> xzcf(@RequestBody SsjcSssjDTO req) {
        List<TycXzcf> xzcf = tycXzcfService.xzcf(req);
/*        long total = xzcf.size();
        if (total == 0) {
            Result<List<TycXzcf>> result = new Result<>();
            return result.error500("查询不到企业的行政处罚数据");
        }*/
        return Result.OK(xzcf);
    }

    @AutoLog(value = "税收违法")
    @PostMapping(value = "/sswf")
    @ApiOperation("税收违法")
    //public Result<Page<TycSswf>> sswf(@RequestBody SsjcSssjDTO req) {
    public Result<List<TycSswf>> sswf(@RequestBody SsjcSssjDTO req) {
        // Page<TycSswf> sswf = tycSswfService.sswf(req);
        List<TycSswf> sswf = tycSswfService.sswf(req);
/*        long total = sswf.size();
        if (total == 0) {
            Result<List<TycSswf>> result = new Result<>();
            return result.error500("查询不到企业的税收违法数据");
        }*/
        return Result.OK(sswf);
    }

//    @AutoLog(value = "税务指标监控结果列表")
//    @PostMapping(value = "/list")
//    public Result<?> list(@RequestBody ZbjkSwzbjkjgQo qo) {
//        // System.out.println(qo.getSsny());
//        List<DjUserInfo> djUserInfos = djUserInfoService.listForPage(qo);
//        List<BgSwzbjcOrder> bgSwzbjcOrders = zbjkSwzbjkjgService.selectList(qo, djUserInfos);
//        Page<BgSwzbjcOrder> page = new Page<>(qo.getPageNo(), qo.getPageSize());
//        PageInfo<BgSwzbjcOrder> pageInfo = new PageInfo<>(bgSwzbjcOrders);
//        page.setRecords(pageInfo.getList());
//        page.setCurrent(qo.getPageNo());
//        page.setTotal(pageInfo.getTotal());
//        page.setSize(qo.getPageSize());
//        Result<Object> result = new Result<>();
//        result.setSuccess(true);
//        result.setResult(page);
//        return result;
//    }
}
